// 基础API url
const config = {
  apiBaseUrl:'https://lengnuanit.top/api',
  apiBaseUrl:'http://127.0.0.1:7001/api',
  token:wx.getStorageSync('token')
}
// 代理模式
const promisic = function (func) {
  return function (params = {}) {
    return new Promise((resolve, reject) => {
      const args = Object.assign(params, {
        success: (res) => {
          resolve(res)
        },
        fail: (error) => {
          reject(error)
        }
      })
      func(args)
    })
  }
}
class  Http {
  static async request({url,data,method='GET'}) {
  // 返回Promise
  const res = await promisic(wx.request)({
     url: `${config.apiBaseUrl}${url}`,
     method,
     data,
     header:{
       token:config.token
     },
   }) 
   if (res.data) {
     return res.data
   }
  }
}

export {
  Http
}